Conversation
MSC29
left a comment
There was a problem hiding this comment.
Recently used this code & stumbled upon a issue when using container objects with spaces in their name...
The hash used the non-encoded path but the temporary url queried agaisnt openstack needs to be url encoded.
| * | ||
| * @param string $method An HTTP method to allow for this temporary URL. Any of GET, POST, HEAD, PUT, POST, DELETE. | ||
| * @param int $expires Unix timestamp | ||
| * @param string $path The full path or storage URL to the Swift object. Example: '/v1/AUTH_account/c/o' or: 'http://saio:8080/v1/AUTH_account/c/o' |
There was a problem hiding this comment.
Hi there. I just re-used this code as I need to generate temporary urls.
It took me a while to notice the issue but here it is in the doc "Do not URL-encode the path when you generate the HMAC-SHA1 signature. However, when you make the actual HTTP request, you should properly URL-encode the URL.".
I'd add this to the doc to ensure an non-encoded $path is passed in.
| // sha512 requires prefixing signature | ||
| $signature = 'sha512' === $digest ? 'sha512:'.$signature : $signature; | ||
|
|
||
| return sprintf('%s?temp_url_sig=%s&temp_url_expires=%s', $path, $signature, $expires); |
There was a problem hiding this comment.
Given the $path is not encoded, I'd suggest encoding the actual temporary url path
| return sprintf('%s?temp_url_sig=%s&temp_url_expires=%s', $path, $signature, $expires); | |
| return sprintf('%s?temp_url_sig=%s&temp_url_expires=%s', urlencode($path), $signature, $expires); |
|
The function returns the Imagine you have a You rather only want the signature, in order to call: It's especially true if a And |
This method loosely follows swift command's way to generate temporary url:
Some features this PR tries to support: